import { inject, injectable } from 'inversify';
import { RoleListModel } from '../models/role.list.model.ts';
import { UsersRolesRepository } from '../data/users.roles.repository.ts';
import { requestUserRolesDTO } from '../data/user.roles.dto.ts';
import { roleListMapper } from '../mappers/role.list.mapper.ts';

@injectable()
export class GetRolesListUseCase {
  constructor(
    @inject(RoleListModel) private roleListModel: RoleListModel,
    @inject(UsersRolesRepository) private rolesRepository: UsersRolesRepository,
  ) {}

  async execute(params: requestUserRolesDTO) {
    try {
      this.roleListModel.loading = true;
      const { data } = await this.rolesRepository.getRolesList(params);

      this.roleListModel.setRoles(roleListMapper(data));
    } finally {
      this.roleListModel.loading = false;
    }
  }
}
